class MyCircularQueue {
    private int[] elem;
    private int front; //队头下标
    private int rear; //队尾下标

    public MyCircularQueue(int k) {
        this.elem = new int[k + 1];
    }

    /**
     * 像队列中添加元素
     * @param value
     * @return
     */
    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }
        elem[rear] = value;
        rear = (rear + 1) % elem.length;
        return true;
    }

    /**
     * 1. 队列为空 不能出
     * 2. 不空 front向后走
     * @return
     */
    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        front = (front + 1) % elem.length;
        return true;
    }

    /**
     * 得到队头元素
     * @return
     */
    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return elem[front];
    }

    /**
     * 得到循环队列的队尾元素
     * @return
     */
    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        int index = (rear - 1 + elem.length) % elem.length;
        return elem[index];
    }

    /**
     * 判断是否队列为空
     * @return
     */
    public boolean isEmpty() {
        return front == rear;
    }

    /**
     * 判断队列是否为满
     * @return
     */
    public boolean isFull() {
        return ((rear + 1) % elem.length) == front;
    }
}